﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Extjs_ReGSharp.Criteria
{
	internal class AndCriteria<T> : ICriteria<T>
	{
		#region Data Members

		List<ICriteria<T>> m_CriteriaList;

		#endregion

		#region Constructor

		public AndCriteria()
		{
			m_CriteriaList = new List<ICriteria<T>>();
		}

		#endregion

		#region Properties

		public int Count
		{
			get
			{
				return m_CriteriaList.Count;
			}
		}

		#endregion

		#region Indexer

		public ICriteria<T> this[int index]
		{
			get
			{
				return m_CriteriaList[index];
			}
		}

		#endregion

		#region Public Methods

		public void AddCriteria(ICriteria<T> criteriaToAdd)
		{
			m_CriteriaList.Add(criteriaToAdd);
		}

		#endregion

		#region ICriteria<T> Members

		public bool IsValid(T instance)
		{
			bool result = true;

			for (int i = 0; i < m_CriteriaList.Count && result; i++)
			{
				ICriteria<T> criteria = m_CriteriaList[i];

				result = criteria.IsValid(instance);
			}

			return result;
		}

		#endregion
	}
}
